package mz.co.research.client.view.component;

import mz.co.research.client.view.model.DataView;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;

public abstract class Table extends FlexTable {

	private DataView dataView;

	private int rowNumber;

	private int startWith;

	public Table(DataView dataView, int startWith) {
		this.dataView = dataView;
		this.startWith = startWith;
		this.init();
	}

	protected void init() {
		for (int i = 0; i < startWith; i++) {
			this.addItem();
		}
	}

	public void reset() {
		for (int i = 0; i < rowNumber; i++) {
			this.removeRow(--rowNumber);
		}
		this.init();
	}

	public void addItem() {
		this.setWidget(rowNumber, 0, createContent());
		rowNumber++;
	}

	public void delItem() {
		if (rowNumber > startWith) {
			this.removeRow(--rowNumber);
		}
	}

	public int getCount() {
		return rowNumber;
	}

	protected abstract Widget createContent();

	public DataView getDataView() {
		return dataView;
	}
}
